Full-Stack

Welcome Portfolio Projects Contact
↑ Go Back ↑

Prompt Engineering Basics Notes

Prompt Engineering Basics Notes

Prompt Engineering:

  • Refining Prompt over multiple instances, adding more information, correcting issues, etc.

General prompt structure

  • Instruction, Context, Input Data, Output Indicators
  • Not a simple description, should usually be a command or question "Write a story about Tom." not simply "Story about Tom"m which would be ambiguous
  • Give context over a thematic before asking the question or command
  • Give Guidelines e.g. how the length and form of the output should be
  • If there is some input data available, include a hint that they exist before the question or command: "There is a data set with temperature values given"
  • Output indicator: Give a "benchmark" for evaluatiing the output, e.g.: "The output must be a story with 300 words. This will be evaluated with clarity and content of therelevant data."

Prompt Formats

For example, the instruction format would work well for a summarization task. For text completion, the statement format would be suitable. When you want to extract a specific entity from a statement, the question format would be most suitable.

  • Question Format: What are the benefits of water reservoirs in a detailed paragraph?
  • Statement Format: Discuss the benefits of utilizing water reservoirs.
  • Instruction Format: List the top five benefits of water reservoirs.
  • You can ask the model for advice how to structure the prompt for a specific task Example: "What's the best way to prompt you to get a flowchart?"
  • Few shot prompting: 2-3 examples (examples don't need to be correct, focus on consistent formatting). GenAI can create more examples
  • Some models have specific syntax (example llama2)

General tips for better prompting

Don't include too specific jargon in the prompt Include examples in the prompt Include from which perspective the output response should be writen (role play)

Tools for Prompt Engineers:

  • IBM watsonsx.ai PromptLab
  • Spellbook (IDE by ScaleAI)
  • Dust
  • PromptPerfect
  • PromptBase

Interview Pattern: multiple messages:

  • "Ask me a series of questions, one by one, to gather all the information you need to give a proper response."

Chain of Thought (CoT)

  • Can break down complex tasks into steps
  • Downside: Produces more output, is slower and can be overcomplicating things
  • Zero-Shot CoT key phrases to append to a prompt for activating CoT:
    • "Let's think step-by-step"
    • "Let's work this out in a step-by-step way to be sure we have the right answer."
  • CoT Reasoning example:
    Answer using the structure given in the example prompts and answers

    Q: Provide a description of a drinking bottle
    A: sturdy, black, good for daily use

    Q: Give a description for a TV
    A: large, 4K, fast, easy to use

    Q: Describe a Treasure Chest
  • Deep Dive using CoT, example:
    Describe the given product with using 1 to 5 words for each category, separated by commas. Do not include the names of the categories:

    - Weight
    - Color
    - Usefulness
    - Compatibility

    Knife

Tree-of-thought approach (ToT)

  • Generate and evaluate multiple possibilities / branches for a given problem
  • Can compare the different possibilities and select from them
  • ToT Example:
    You have to find the best strategy to stay up to date with current technology advancements. I'm able to pay 20$ per year for this.

    Follow this structure:

    List three different solutions (label them A, B, C)
    For each solution, list:
    a. Information sources
    b. Amount of effort needed
    c. Cost

    Compare the solutions and choose the best one. Explain why it is better than the others.

Playoff method

  • A prompt which is used to generate multiple prompts which get evaluated and compared automatically by the LLM to each other.
  • Example:
    Provide 5 different text prompts, asking to generate a short welcome message for a bar.
    Include the following elements:
    1. The name of the bar "BarZ"
    2. keep it in a happy mood

    For each set of responses, perform a detailed pairwise comparison between every possible pair based on the following criteria: clarity of expression and coverage of the requirements. Clearly state which response is stronger in each comparison, and then determine the overall strongest response by aggregating these pairwise results.

Image Prompting

  • image prompt = description of an image
  • Techniques:
    • Style modifiers: Photographic, Animated, Digital Art, Comic Book, Fantasy Art, Line Art, Analog Film, Neon Punk, Isometric, Origami, Cinematic Pixel Art, etc.
    • Quality boosters: 4K, realistic, etc.
    • Repetition: repeat words, example: "image of a red, red, red, white cat"
    • Weighted terms: image of a cat using |red: 8|white: 1
    • Fix deformed generation: negative prompts, -deformed, -ugly, etc.
  • Ask an LLM to generate a well-structured prompt for DALL-E 2 and describe what the image should contain.